// WaveeditorDialogs.cpp : implementation file
//

#include "stdafx.h"
#include "waveeditor.h"
#include "WaveeditorDialogs.h"
#include "languagecomponents.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// WritingSatusDialog dialog


WritingSatusDialog::WritingSatusDialog(CWnd* pParent /*=NULL*/)
	: CDialog(WritingSatusDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(WritingSatusDialog)
	//}}AFX_DATA_INIT
}


void WritingSatusDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

	//{{AFX_DATA_MAP(WritingSatusDialog)
	DDX_Control(pDX, IDC_SCRIPTNAME, m_scriptname);
	DDX_Control(pDX, IDC_NUMBEROFLINES, m_cnumberoflines);
	DDX_Control(pDX, IDC_LINENUMBER, m_clinenumber);
	DDX_Control(pDX, IDC_FRAMENAME, m_cframename);
	DDX_Control(pDX, IDC_FRAME, m_cframe);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(WritingSatusDialog, CDialog)
	//{{AFX_MSG_MAP(WritingSatusDialog)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// WritingSatusDialog message handlers

void WritingSatusDialog::SetFrame(CString sframe)
{
	m_cframe.SetSel(0,-1);
	m_cframe.Clear();
	m_cframe.ReplaceSel(sframe);
}

void WritingSatusDialog::SetFrameName(CString framename)
{
	m_cframename.SetSel(0,-1);
	m_cframename.Clear();
	m_cframename.ReplaceSel(framename);
}

void WritingSatusDialog::SetNumberOfLines(unsigned __int64 num)
{
	m_cnumberoflines.SetSel(0,-1);
	m_cnumberoflines.Clear();
	char number[20];
	_i64toa(num,number,10);
	m_cnumberoflines.ReplaceSel(number);
}

void WritingSatusDialog::SetLineNumber(unsigned long num)
{
	m_clinenumber.SetSel(0,-1);
//	m_clinenumber.Clear();
	char number[20];
	_i64toa(num,number,10);
	m_clinenumber.ReplaceSel(number);
}

void WritingSatusDialog::SetScriptName(CString name)
{
	m_scriptname.SetSel(0,-1);
	m_scriptname.Clear();
	m_scriptname.ReplaceSel(name);
}



////////////////////////////////////////////////
// ReadingModeDialog dialog

BEGIN_MESSAGE_MAP(ReadingModeDialog, CDialog)
	ON_BN_CLICKED(IDC_BRACKETS_YES_RADIO, OnBracketsYes)
	ON_BN_CLICKED(IDC_BRACKETS_NO_RADIO, OnBracketsNo)
	ON_BN_CLICKED(IDC_NO_BRACKETS_YES_RADIO, OnNoBracketsYes)
	ON_BN_CLICKED(IDC_NO_BRACKETS_NO_RADIO, OnNoBracketsNo)
	ON_BN_CLICKED(IDC_GET_WHOLE_LOG, OnGetWholeLog)
END_MESSAGE_MAP()

IMPLEMENT_DYNAMIC(ReadingModeDialog, CDialog)
ReadingModeDialog::ReadingModeDialog( const LogReadingType &NewReadType, CWnd* pParent /*=NULL*/)
	: CDialog(ReadingModeDialog::IDD, pParent)
{
	OldReadType = NewReadType;
}

ReadingModeDialog::~ReadingModeDialog()
{
}

void ReadingModeDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	if ( ((CButton *)GetDlgItem( IDC_BRACKETS_YES_RADIO ))->GetCheck() == BST_CHECKED )
	{
		ReadType.TypeOfBracketLines =  ( ((CButton *)GetDlgItem( IDC_BRACKETS_WORD_RADIO ))->GetCheck() == BST_CHECKED )? BY_WORD : BY_STRING;
	}
	else
	{
		ReadType.TypeOfBracketLines = NO_READ;
	}
	if ( ((CButton *)GetDlgItem( IDC_NO_BRACKETS_YES_RADIO ))->GetCheck() == BST_CHECKED )
	{
		ReadType.TypeOfNoBracketLines =  ( ((CButton *)GetDlgItem( IDC_NO_BRACKETS_WORD_RADIO ))->GetCheck() == BST_CHECKED )? BY_WORD : BY_STRING;
	}
	else
	{
		ReadType.TypeOfNoBracketLines = NO_READ;
	}
}

LogReadingType ReadingModeDialog::GetReadType()
{
	return ReadType;
}

BOOL ReadingModeDialog::OnInitDialog() 
{
    CDialog::OnInitDialog();
	switch( OldReadType.TypeOfBracketLines )
	{
	case NO_READ:
		{
			((CButton *)GetDlgItem( IDC_BRACKETS_NO_RADIO ))->SetCheck( BST_CHECKED );
			((CButton *)GetDlgItem( IDC_BRACKETS_WORD_RADIO ))->SetCheck( BST_CHECKED );
			GetDlgItem( IDC_BRACKETS_TYPE_STATIC )->EnableWindow( FALSE );
			GetDlgItem( IDC_BRACKETS_WORD_RADIO )->EnableWindow( FALSE );
			GetDlgItem( IDC_BRACKETS_STRING_RADIO )->EnableWindow( FALSE );
			break;
		}
	case BY_STRING:
		{
			((CButton *)GetDlgItem( IDC_BRACKETS_YES_RADIO ))->SetCheck( BST_CHECKED );
			((CButton *)GetDlgItem( IDC_BRACKETS_STRING_RADIO ))->SetCheck( BST_CHECKED );
			break;
		}
	default:
		{
			((CButton *)GetDlgItem( IDC_BRACKETS_YES_RADIO ))->SetCheck( BST_CHECKED );
			((CButton *)GetDlgItem( IDC_BRACKETS_WORD_RADIO ))->SetCheck( BST_CHECKED );
			break;
		}
	}
	
	switch( OldReadType.TypeOfNoBracketLines )
	{
	case NO_READ:
		{
			((CButton *)GetDlgItem( IDC_NO_BRACKETS_NO_RADIO ))->SetCheck( BST_CHECKED );
			((CButton *)GetDlgItem( IDC_NO_BRACKETS_WORD_RADIO ))->SetCheck( BST_CHECKED );
			GetDlgItem( IDC_NO_BRACKETS_TYPE_STATIC )->EnableWindow( FALSE );
			GetDlgItem( IDC_NO_BRACKETS_WORD_RADIO )->EnableWindow( FALSE );
			GetDlgItem( IDC_NO_BRACKETS_STRING_RADIO )->EnableWindow( FALSE );
			break;
		}
	case BY_STRING:
		{
			((CButton *)GetDlgItem( IDC_NO_BRACKETS_YES_RADIO ))->SetCheck( BST_CHECKED );
			((CButton *)GetDlgItem( IDC_NO_BRACKETS_STRING_RADIO ))->SetCheck( BST_CHECKED );
			break;
		}
	default:
		{
			((CButton *)GetDlgItem( IDC_NO_BRACKETS_YES_RADIO ))->SetCheck( BST_CHECKED );
			((CButton *)GetDlgItem( IDC_NO_BRACKETS_WORD_RADIO ))->SetCheck( BST_CHECKED );
			break;
		}
	}
	
    return TRUE;   // return TRUE unless you set the focus to a control
}




// ReadingModeDialog message handlers

void ReadingModeDialog::OnBracketsYes()
{
	GetDlgItem( IDC_BRACKETS_TYPE_STATIC )->EnableWindow( TRUE );
	GetDlgItem( IDC_BRACKETS_WORD_RADIO )->EnableWindow( TRUE );
	GetDlgItem( IDC_BRACKETS_STRING_RADIO )->EnableWindow( TRUE );
}

void ReadingModeDialog::OnBracketsNo()
{
	GetDlgItem( IDC_BRACKETS_TYPE_STATIC )->EnableWindow( FALSE );
	GetDlgItem( IDC_BRACKETS_WORD_RADIO )->EnableWindow( FALSE );
	GetDlgItem( IDC_BRACKETS_STRING_RADIO )->EnableWindow( FALSE );
}

void ReadingModeDialog::OnNoBracketsYes()
{
	GetDlgItem( IDC_NO_BRACKETS_TYPE_STATIC )->EnableWindow( TRUE );
	GetDlgItem( IDC_NO_BRACKETS_WORD_RADIO )->EnableWindow( TRUE );
	GetDlgItem( IDC_NO_BRACKETS_STRING_RADIO )->EnableWindow( TRUE );
}

void ReadingModeDialog::OnNoBracketsNo()
{
	GetDlgItem( IDC_NO_BRACKETS_TYPE_STATIC )->EnableWindow( FALSE );
	GetDlgItem( IDC_NO_BRACKETS_WORD_RADIO )->EnableWindow( FALSE );
	GetDlgItem( IDC_NO_BRACKETS_STRING_RADIO )->EnableWindow( FALSE );
}

void ReadingModeDialog::OnGetWholeLog()
{
	UpdateData();
	EndDialog( ID_GET_ALL );
}